/*
 * @Author: TT-hzy 
 * @Date: 2024-05-05 16:19:07
 * @LastEditors: TT-hzy 
 * @LastEditTime: 2024-05-05 17:02:05
 * @Description: 
 */

import 'package:flutter/material.dart';
import '../extensions/theme_extension.dart';
import 'widgets.dart';

enum CommonPlaceHoldType {
  /// 无网络
  noNetwork,

  /// 未登录
  noLogin,

  ///空数据
  emptyData,
}

class PlaceHoldPage extends StatefulWidget {
  const PlaceHoldPage({
    super.key,
    required this.placeHoldType,
    this.onTap,
    this.btnMsg,
    this.title,
    this.msg,
  });
  final CommonPlaceHoldType placeHoldType;
  final String? msg;
  final String? title;
  final String? btnMsg;
  final Function? onTap;
  @override
  State<StatefulWidget> createState() {
    return _PlaceHoldPageState();
  }
}

class _PlaceHoldPageState extends State<PlaceHoldPage> {
  /// 属性
  ///
  ///

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white.withAlpha(0),
      ),
      alignment: Alignment.center,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          configPlaceWidget(type: 1),
          const SizedBox(
            height: 15,
          ),
          configPlaceWidget(type: 2),
          const SizedBox(
            height: 15,
          ),
          configPlaceWidget(type: 4),
        ],
      ),
    );
  }

  /// 创建暂位图
  Widget createPlaceImageWidget() {
    Widget body = configEmptyDataWidget();
    return body;
  }

  /// 创建暂位图标语
  Widget createPlaceTitleWidget() {
    String title = "";
    if (widget.placeHoldType == CommonPlaceHoldType.noNetwork) {
      title = "暂无网络,请稍后重试";
    } else if (widget.placeHoldType == CommonPlaceHoldType.emptyData) {
      title = "暂无数据";
    }
    title = widget.msg ?? title;
    return Text(
      title,
      style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
      textAlign: TextAlign.center,
    );
  }

  /// 创建暂位图描述语
  Widget createPlaceMessageWidget() {
    return Container();
  }

  /// 创建暂位图 刷新按钮
  Widget createPlaceReloadBtnWidget() {
    return InkWell(
      onTap: () async {
        widget.onTap?.call();
      },
      child: Container(
        alignment: Alignment.center,
        width: 100,
        height: 40,
        decoration: BoxDecoration(
          color: context.primaryColor,
          borderRadius: const BorderRadius.all(
            Radius.circular(20),
          ),
        ),
        child: Text(
          widget.btnMsg ?? "刷新",
          style: const TextStyle(
            fontSize: 14,
            color: Colors.white,
            fontWeight: FontWeight.bold,
          ),
        ),
      ),
    );
  }

  /// 触发方法
  ///
  ///
  Widget configPlaceWidget({
    int type = 1,
  }) {
    Widget? child = Container();
    switch (type) {
      case 1:
        child = createPlaceImageWidget();
        break;
      case 2:
        child = createPlaceTitleWidget();
        break;
      case 3:
        child = createPlaceMessageWidget();
        break;
      case 4:
        child = createPlaceReloadBtnWidget();
        break;
      default:
    }
    return child;
  }
}
